package com.example.cms.controller;

import com.example.cms.entity.User;
import com.example.cms.service.UserService;
import com.example.cms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

   @PostMapping("/create")
    public void create(@RequestBody User user){
       userService.create(user);
   }

   @PostMapping("/delete")
    public void delete(Integer id){
       userService.delete(id);
   }

   @PostMapping("/update")
    public void update(@RequestBody User user){
        userService.update(user);
   }

   @PostMapping("/query")
    public Result query(@RequestBody User user){
       List<User> list = userService.query(user);
       System.out.println(1/0);
       return Result.ok(list);
   }

   @PostMapping("/detail")
   public Result detail(Integer id){
       User user = userService.detail(id);
       return Result.ok(user);
   }

    @PostMapping("/count")
    public Result count(@RequestBody User user){
        Integer count = userService.count(user);
        return Result.ok(count);
    }





}
